import { Component, OnInit } from '@angular/core';
import { AppPaginationComponent, PaginationModel } from "../../../../widgets/pagination/pagination.component";
import { InvestService } from './invest.service';
import { Router, NavigationEnd, ActivatedRoute } from '@angular/router';
import { environment } from '../../../../../environments/environment';

@Component({
  selector: 'app-invest',
  templateUrl: './invest.component.html',
  styleUrls: ['./invest.component.scss'],
  providers: [InvestService]
})
export class InvestComponent implements OnInit {

  // 从路由获取内码
  public nFundNo: any

  // 投资经理列表数据
  public investList: any;

  // 企业年金投资经理分页配置
  public investListPageInfo: PaginationModel = {
    currentPageNum: 1,
    pageSize: 10,
    totalPages: 1,
    total: 0,
    pagesShow: 5,
    startRow: 0,
    endRow: 0,
    pageList: [5, 10, 25, 50, 100]
  };

  // 企业年金投资经理列表body
  public investPageBody: any = {
    "nFundNo": '',
    "pageIndex": 1,
    "pageSize": 10
  }

  constructor(
    public investService: InvestService,
    private route: ActivatedRoute
  ) {
    this.route.params.subscribe((data) => {
      this.nFundNo = data.nFundNo;
      this.investPageBody.nFundNo = data.nFundNo
      console.log('----------nfundno');
      console.log(this.nFundNo);
    });
    this.list();
  }


  // 企业年金投资经理列表分页
  investPageNavigation(currentPageNum: number) {
    this.investListPageInfo.currentPageNum = currentPageNum;
    this.list(this.investListPageInfo.currentPageNum, this.investListPageInfo.pageSize);
  }

  // 企业年金投资经理列表切换页
  investPagesizeChange(pageSize: number) {
    if (pageSize !== this.investListPageInfo.pageSize) {
      this.investListPageInfo.pageSize = pageSize;
      this.list();
    }
  }
  list(pageNum?, pageSize?) {
    let that = this;
    // this.isCheckedAll = false;
    // 查询条件转码
    this.investPageBody.pageIndex = pageNum ? pageNum : this.investListPageInfo.currentPageNum;
    this.investPageBody.pageSize = pageSize ? pageSize : this.investListPageInfo.pageSize;
    this.investService.list(this.investPageBody).subscribe(data => {
      if (data) {
        that.investList = data.list;
        that.investListPageInfo.currentPageNum = data.pageNum;
        that.investListPageInfo.totalPages = data.pages;
        that.investListPageInfo.total = data.total;
        that.investListPageInfo.startRow = data.startRow;
        that.investListPageInfo.endRow = data.endRow;
        console.log(that.investList);
      }
    })
  }

  // 导出
  exportExcel() {
    let getBody = {
      "nFundNo": this.nFundNo
    }
    const iframe = window['$']("<iframe id='downloadiframe'>");
    iframe.attr('style', 'display:none');
    iframe.attr('src', environment.server + '/pms/1/common/investManager/export/list?token=' + sessionStorage.getItem('token') + '&nFundNo=' + getBody.nFundNo);
    window['$']('body').append(iframe);
    setTimeout("$('#downloadiframe').remove()", 60000);
  }


  
  ngOnInit() {

  }

}
